package com.fz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fz.entity.Visitor;
import com.fz.mapper.VisitorMapper;
import com.fz.service.VisitorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 存储访客信息 服务实现类
 * </p>
 *
 * @author hyr
 * @since 2025-06-18
 */
@Service
public class VisitorServiceImpl extends ServiceImpl<VisitorMapper, Visitor> implements VisitorService {
    @Override
    public boolean check(Long id,String field,String value)
    {
        QueryWrapper<Visitor> wrapper=new QueryWrapper<>();
        wrapper.eq(field,value);
        System.out.println(id);
        if(null!=id)
        {
            wrapper.ne("id",id);
        }
        return this.count(wrapper)==0;
    }
    @Override
    public Page<Visitor> getList(String username, Integer pageNo, Integer pageSize) {
        QueryWrapper<Visitor> wrapper = new QueryWrapper<>();
        Page<Visitor>visitorPage;
        wrapper.eq("username", username)
                .ne("status",-1)
                .orderByDesc("create_time");
        visitorPage = this.page(new Page<>(pageNo, pageSize), wrapper);
        return visitorPage;
    }

    @Override
    public Boolean add(String type, String aging, Integer count, String content, Integer userId, String username){

        return this.save(new Visitor(type,aging,count,content,Long.valueOf(userId),username));
    }


    @Override
    public boolean reject(Long id, Integer statue, Integer statu){
        return this.updateById(new Visitor(id,statue,statu));
    }
    @Override
    public boolean pass(Long id, Integer statue, Integer statu){

        return this.updateById(new Visitor(id,statue,statu));
    }

    @Override
    public boolean del(Long id, Integer status) {
        return this.updateById(new Visitor(id,status));
    }

    @Override
    public Page<Visitor> search(String input, Integer pageNo, Integer pageSize){
        QueryWrapper<Visitor> wrapper=new QueryWrapper<>();
        Page<Visitor>visitorPage;
        wrapper.like("username",input)
                .ne("status",-1)
                .orderByDesc("create_time");
        visitorPage = this.page(new Page<>(pageNo, pageSize), wrapper);
        return this.page(new Page<>(pageNo, pageSize),wrapper);
    }
    @Override
    public Page<Visitor> showList(Integer pageNo, Integer pageSize) {
        QueryWrapper<Visitor> wrapper = new QueryWrapper<>();
        Page<Visitor>visitorPage;
        wrapper.ne("status",-1)
                .orderByDesc("create_time");
        visitorPage = this.page(new Page<>(pageNo, pageSize), wrapper);
        return this.page(new Page<>(pageNo, pageSize),wrapper);
    }


}
